package com.sub.json;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPatch;
import com.alibaba.fastjson.JSONPath;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName JsonObjectTest
 * @Description: TODO
 * @Author Submerge.
 * @Since 2023/11/24 14:27
 * @Version 1.0
 */
public class JsonObjectTest {

    public static void main(String[] args) {

        JSONObject jsonObject = new JSONObject();
        if (jsonObject.isEmpty()){
            jsonObject.put("name","subing");
        }
        Object o = jsonObject.get("name");
        System.out.println(o);

        HashMap<String, Object> m = new HashMap<>();
        m.put("username","12345");
        m.put("password","56789");
        jsonObject.put("info",m);
        jsonObject.put("data",null);
        int size = jsonObject.size();
        System.out.println(size);
        JSONObject info = jsonObject.getJSONObject("info");
        Object o1 = info.get("username");
        Object o2 = info.get("password");
        JSONObject data = jsonObject.getJSONObject("data");
        JSONArray jsonArray = new JSONArray();


        String jsonArrayStr = "{\n" +
                "  \"themeId\": \"1672071601529618434\",\n" +
                "  \"themeName\": \"能力中心\",\n" +
                "  \"themeResType\": \"1|2|3|4\",\n" +
                "  \"themeLevel\": 1,\n" +
                "  \"themePid\": \"0\",\n" +
                "  \"themePids\": \"[0]\",\n" +
                "  \"themeNamePath\": \"能力中心\",\n" +
                "  \"themeSort\": 2,\n" +
                "  \"icon\": null,\n" +
                "  \"status\": 0,\n" +
                "  \"createUser\": null,\n" +
                "  \"createUserName\": null,\n" +
                "  \"createTime\": \"2023-06-23 10:38:30\",\n" +
                "  \"updateUser\": \"1669177435349667841\",\n" +
                "  \"updateUserName\": \"杰瑞吴\",\n" +
                "  \"updateTime\": \"2023-07-07 16:08:04\",\n" +
                "  \"isLeaf\": false,\n" +
                "  \"groupId\": \"0\",\n" +
                "  \"groupName\": null,\n" +
                "  \"group2Id\": \"0\",\n" +
                "  \"group2Name\": null,\n" +
                "  \"childrenList\": [\n" +
                "    {\n" +
                "      \"themeId\": \"1672073076288847873\",\n" +
                "      \"themeName\": \"调查监测\",\n" +
                "      \"themeResType\": null,\n" +
                "      \"themeLevel\": 2,\n" +
                "      \"themePid\": \"1672071601529618434\",\n" +
                "      \"themePids\": \"[0][1672071601529618434]\",\n" +
                "      \"themeNamePath\": \"能力中心/调查监测\",\n" +
                "      \"themeSort\": 1,\n" +
                "      \"icon\": \"3Dh23r-W0BbAOD_7qnVwZcD0CGzqwp8UtAKt9TJvYtobN9PwdvH7h2MD4GWq1Nrc2CD5gZExcQmj-v6oTjP9vDQ\",\n" +
                "      \"status\": 0,\n" +
                "      \"createUser\": null,\n" +
                "      \"createUserName\": null,\n" +
                "      \"createTime\": \"2023-06-23 10:44:22\",\n" +
                "      \"updateUser\": \"1669177435349667841\",\n" +
                "      \"updateUserName\": \"吴经纬\",\n" +
                "      \"updateTime\": \"2023-11-14 16:58:36\",\n" +
                "      \"isLeaf\": false,\n" +
                "      \"groupId\": \"1672071601529618434\",\n" +
                "      \"groupName\": \"能力中心\",\n" +
                "      \"group2Id\": \"1672073076288847873\",\n" +
                "      \"group2Name\": \"调查监测调查监测调查监测调查监测调查监测调查监测调查监测调查\",\n" +
                "      \"childrenList\": [\n" +
                "        {\n" +
                "          \"themeId\": \"1677136463977283585\",\n" +
                "          \"themeName\": \"测试添加一级分类-修改\",\n" +
                "          \"themeResType\": null,\n" +
                "          \"themeLevel\": 3,\n" +
                "          \"themePid\": \"1672073076288847873\",\n" +
                "          \"themePids\": \"[0][1672071601529618434][1672073076288847873]\",\n" +
                "          \"themeNamePath\": \"能力中心/调查监测/测试添加一级分类-修改\",\n" +
                "          \"themeSort\": 1,\n" +
                "          \"icon\": \"3TLBKrhVVrlEMHvmfLFdC7lcoaxzZRdsyIuKGuO7ub0nkXpXUTDqYsLxhKXrpef1cfDriZqDQZx4-x08EZGv5hg\",\n" +
                "          \"status\": 0,\n" +
                "          \"createUser\": \"1669631703084916738\",\n" +
                "          \"createUserName\": \"李杨佳发\",\n" +
                "          \"createTime\": \"2023-07-07 10:04:27\",\n" +
                "          \"updateUser\": \"1669177435349667841\",\n" +
                "          \"updateUserName\": \"吴经纬\",\n" +
                "          \"updateTime\": \"2023-11-14 16:58:36\",\n" +
                "          \"isLeaf\": false,\n" +
                "          \"groupId\": \"1672071601529618434\",\n" +
                "          \"groupName\": \"能力中心\",\n" +
                "          \"group2Id\": \"1672073076288847873\",\n" +
                "          \"group2Name\": \"调查监测调查监测调查监测调查监测调查监测调查监测调查监测调查\",\n" +
                "          \"childrenList\": [\n" +
                "            {\n" +
                "              \"themeId\": \"1677136736149864449\",\n" +
                "              \"themeName\": \"测试添加一级分类-修改-创建二级分类-修改\",\n" +
                "              \"themeResType\": null,\n" +
                "              \"themeLevel\": 4,\n" +
                "              \"themePid\": \"1677136463977283585\",\n" +
                "              \"themePids\": \"[0][1672071601529618434][1672073076288847873][1677136463977283585]\",\n" +
                "              \"themeNamePath\": \"能力中心/调查监测/测试添加一级分类-修改/测试添加一级分类-修改-创建二级分类-修改\",\n" +
                "              \"themeSort\": 1,\n" +
                "              \"icon\": \"3NRIZDctNiKgN_SpQVBvYDV76-nQ8BCO_ghFGDJgU9tmIzhs9NqXqteTaFjDXnnswFbJnhVaJrpIAo2NzmPb2Ow\",\n" +
                "              \"status\": 0,\n" +
                "              \"createUser\": \"1669631703084916738\",\n" +
                "              \"createUserName\": \"李杨佳发\",\n" +
                "              \"createTime\": \"2023-07-07 10:05:32\",\n" +
                "              \"updateUser\": \"1669177435349667841\",\n" +
                "              \"updateUserName\": \"吴经纬\",\n" +
                "              \"updateTime\": \"2023-11-14 16:58:36\",\n" +
                "              \"isLeaf\": true,\n" +
                "              \"groupId\": \"1672071601529618434\",\n" +
                "              \"groupName\": \"能力中心\",\n" +
                "              \"group2Id\": \"1672073076288847873\",\n" +
                "              \"group2Name\": \"调查监测调查监测调查监测调查监测调查监测调查监测调查监测调查\",\n" +
                "              \"childrenList\": null\n" +
                "            }\n" +
                "          ]\n" +
                "        }\n" +
                "      ]\n" +
                "    },\n" +
                "    {\n" +
                "      \"themeId\": \"1672073101928628225\",\n" +
                "      \"themeName\": \"审批监管\",\n" +
                "      \"themeResType\": null,\n" +
                "      \"themeLevel\": 2,\n" +
                "      \"themePid\": \"1672071601529618434\",\n" +
                "      \"themePids\": \"[0][1672071601529618434]\",\n" +
                "      \"themeNamePath\": \"能力中心/审批监管\",\n" +
                "      \"themeSort\": 2,\n" +
                "      \"icon\": \"33f_6qlaZMoli9HtWS7G6pGtlYhrq8SOo8ScLicnjXo71C46ItrvAg1Mu6Uamj7Bp\",\n" +
                "      \"status\": 0,\n" +
                "      \"createUser\": null,\n" +
                "      \"createUserName\": null,\n" +
                "      \"createTime\": \"2023-06-23 10:44:28\",\n" +
                "      \"updateUser\": \"1670248002399985666\",\n" +
                "      \"updateUserName\": \"卢锦涛\",\n" +
                "      \"updateTime\": \"2023-07-11 10:08:16\",\n" +
                "      \"isLeaf\": true,\n" +
                "      \"groupId\": \"1672071601529618434\",\n" +
                "      \"groupName\": \"能力中心\",\n" +
                "      \"group2Id\": \"1672073101928628225\",\n" +
                "      \"group2Name\": \"审批监管\",\n" +
                "      \"childrenList\": null\n" +
                "    },\n" +
                "    {\n" +
                "      \"themeId\": \"1672073124040998913\",\n" +
                "      \"themeName\": \"评价评估\",\n" +
                "      \"themeResType\": null,\n" +
                "      \"themeLevel\": 2,\n" +
                "      \"themePid\": \"1672071601529618434\",\n" +
                "      \"themePids\": \"[0][1672071601529618434]\",\n" +
                "      \"themeNamePath\": \"能力中心/评价评估\",\n" +
                "      \"themeSort\": 3,\n" +
                "      \"icon\": \"3DoJC2GKzedjdaqtBkg7N7p1sm5RJxNFheuj8m4JpndPSB7DhIqnMAxndPFNjYgLl\",\n" +
                "      \"status\": 0,\n" +
                "      \"createUser\": null,\n" +
                "      \"createUserName\": null,\n" +
                "      \"createTime\": \"2023-06-23 10:44:33\",\n" +
                "      \"updateUser\": \"1670248002399985666\",\n" +
                "      \"updateUserName\": \"卢锦涛\",\n" +
                "      \"updateTime\": \"2023-07-11 10:08:23\",\n" +
                "      \"isLeaf\": true,\n" +
                "      \"groupId\": \"1672071601529618434\",\n" +
                "      \"groupName\": \"能力中心\",\n" +
                "      \"group2Id\": \"1672073124040998913\",\n" +
                "      \"group2Name\": \"评价评估\",\n" +
                "      \"childrenList\": null\n" +
                "    },\n" +
                "    {\n" +
                "      \"themeId\": \"1672073145935265793\",\n" +
                "      \"themeName\": \"预警预测\",\n" +
                "      \"themeResType\": null,\n" +
                "      \"themeLevel\": 2,\n" +
                "      \"themePid\": \"1672071601529618434\",\n" +
                "      \"themePids\": \"[0][1672071601529618434]\",\n" +
                "      \"themeNamePath\": \"能力中心/预警预测\",\n" +
                "      \"themeSort\": 4,\n" +
                "      \"icon\": \"3d6KDqZyct6CXW1nFqn5ML7umkbK7u1EkXl5okfBYvu40NaDnnB4_wAUHpVGXzaeD\",\n" +
                "      \"status\": 0,\n" +
                "      \"createUser\": null,\n" +
                "      \"createUserName\": null,\n" +
                "      \"createTime\": \"2023-06-23 10:44:38\",\n" +
                "      \"updateUser\": \"1670248002399985666\",\n" +
                "      \"updateUserName\": \"卢锦涛\",\n" +
                "      \"updateTime\": \"2023-07-11 10:08:36\",\n" +
                "      \"isLeaf\": true,\n" +
                "      \"groupId\": \"1672071601529618434\",\n" +
                "      \"groupName\": \"能力中心\",\n" +
                "      \"group2Id\": \"1672073145935265793\",\n" +
                "      \"group2Name\": \"预警预测\",\n" +
                "      \"childrenList\": null\n" +
                "    },\n" +
                "    {\n" +
                "      \"themeId\": \"1672073173084995585\",\n" +
                "      \"themeName\": \"赋能中心\",\n" +
                "      \"themeResType\": null,\n" +
                "      \"themeLevel\": 2,\n" +
                "      \"themePid\": \"1672071601529618434\",\n" +
                "      \"themePids\": \"[0][1672071601529618434]\",\n" +
                "      \"themeNamePath\": \"能力中心/赋能中心\",\n" +
                "      \"themeSort\": 5,\n" +
                "      \"icon\": \"3yhpDsMrg12ZuFHLuxgWOh5YyHqephmYLG-Hiuj1wAgZOOT8E7WRfI77LeVWB17GZ\",\n" +
                "      \"status\": 0,\n" +
                "      \"createUser\": null,\n" +
                "      \"createUserName\": null,\n" +
                "      \"createTime\": \"2023-06-23 10:44:45\",\n" +
                "      \"updateUser\": \"1670248002399985666\",\n" +
                "      \"updateUserName\": \"卢锦涛\",\n" +
                "      \"updateTime\": \"2023-07-11 10:08:45\",\n" +
                "      \"isLeaf\": true,\n" +
                "      \"groupId\": \"1672071601529618434\",\n" +
                "      \"groupName\": \"能力中心\",\n" +
                "      \"group2Id\": \"1672073173084995585\",\n" +
                "      \"group2Name\": \"赋能中心\",\n" +
                "      \"childrenList\": null\n" +
                "    }\n" +
                "  ]\n" +
                "}";

        JSONObject object = JSONObject.parseObject(jsonArrayStr);
        List<Map<String, Object>> themeList = (List<Map<String, Object>>) JSONPath.eval(object, "$..[?(@.themeId && @.themeName)]");        for (Map eval : themeList) {
            if (eval.containsKey("themeName")){
                System.out.println(eval.get("theme"));
                System.out.println(eval.get("themeId"));
                System.out.println("===============");
            }
        }



    }
}
